<template>
    <div class="page offlineWork-page" data-page="offlineWork" style="z-index: 2;">
        <div class="link-page-nav" style="height:100%">
            <div style="height:40px">
                <a href="#" class="link" @click="offlineWork_over">
                    <i class="iconfont icon-cha" style="font-size:15px;margin-top: 10px;"></i>
                </a>
                <span class="offline_title">离线作业</span>
                <div class="offline_over_work" @click="offlineWork_over">结束作业</div>
            </div>
            <div class="apply-permiss-offline" @click="goNewCheckApply">
                <div class="item-media">
                    <div class="item-media-icon greenC">
                        <i class="iconfont icon-APPgongzuotaileixingtubiao_richangxunjian"></i>
                    </div>
                </div>
                <div class="item-inner">
                    <div class="item-title"><span>日常巡检</span></div>
                </div>
                <i class="iconfont icon-jiantou" style="float: right;margin-top: -27px;"></i>
            </div>
            <div class="page-content offlineWork_content" style="padding-bottom: 25px;height:calc(100% - 110px);">
                <div class="offlineWork_content">
                    <div class="offlineWork_content_title">
                        <div class='offlineWork_content_top'>
                            <span style="color: #999999;"><i class="iconfont icon-weixiuon"
                                    style="font-size: 14px;margin-right:3px"></i>维保助手提醒您:</span>
                            <!-- <i class="iconfont icon-APPicon_guanbi close-maintencePopup" style="font-size: 12px;float: right;"></i> -->
                        </div>
                        <div class='offlineWork_content_bto'>你当前正在进行<span id="maintence_total">0</span>项维保任务</div>
                    </div>
                    <div class="page-content cotent infinite-scroll-content">
                        <div class="delay-task-list">
                            <ul id="delayTaskList_list"></ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    return {
        mounted() {
            var self = this;
            var app = self.$app;
            //页面传参
            self.orgId = this.$route.params.orgId;
            self.dayCheck = this.$route.params.dayCheck;
            self.dayWeibao = this.$route.params.dayWeibao;
        },
        data: function () {
            return {
                pageName: "offlineWork",
                currentTestData: [],
                maintencePopup: '',
                downInterval_delay: 0,
                downInterval_popup: 0,
                downInterval: 0,
                downInterval_pop: 0,
                downInterval_task: 0,
                isHasTest: false,
                isShowPop: false,
                currentTestEndTime: '',
                proportion: 0,
                yuanBox: null,
                clickNum: 0,
                timer: null,
                process: 0,
                success: '',
                total: '',
            }
        },
        methods: {
            refreshCurrent: function () {//刷新

            },
            goNewCheckApply: function () {//日常巡检跳转
                app.router.navigate("/checkApply/1/0/0/0/")
            },
            offlineWork_over: function () {//结束离线作业
                let self = this
                loadofflineWorkupload(function (data) {
                    native.saveDataByKey("IS_OFFLINE_POPUP", 1);//弹窗出来后禁止返回
                    jQuery(".start_offlineWork_cancel").off().on('click', function (e) {
                        native.saveDataByKey("IS_OFFLINE_POPUP", 0);
                        app.popup.close()
                        jQuery(".ilink-popup-backdrop").remove()
                    })
                    // 确定结束离线作业
                    jQuery(".start_offlineWork_sure").off().on('click', function (e) {
                        jQuery(".load_add_offline").hide()
                        jQuery(".load_loading_offline").show()

                        native.checkOfflineCommitData(function (status, info, total, success, faild) {
                            self.total = total;
                            self.success = success;
                            if (status == 1) {
                                // 网络异常
                                app.methods.showToastCenter(info);
                                jQuery(".ilink-popup-backdrop").remove()
                                native.saveDataByKey("IS_OFFLINE_POPUP", 0);
                                app.popup.close();
                            } else if (status == 2) {
                                // 无需要提交的作业数据
                                jQuery(".load_loading_offline").hide()
                                jQuery(".load_add_offline").hide()
                                jQuery(".load_none_offline").show()
                            } else {
                                jQuery(".load_add_offline").hide()
                                jQuery(".load_loading_offline").show()

                                self.proportion = parseInt((success + faild) / total * 100)

                                self.progressBar(self.proportion)
                                yuanBox.gx(0)
                                jQuery(".boxnum")[0].innerText = "0%"
                                yuanBox.gx(0)
                                if (faild > 0 && self.proportion == 100) {
                                    jQuery(".load_loading_offline").hide()
                                    jQuery(".load_fails_offline").show()
                                    self.proportion = 0
                                    self.progressBar(self.proportion)
                                    return
                                } else if (success == total && jQuery(".boxnum")[0].innerText == "100%") {
                                    
                                }
                            }
                        });
                    })
                    // 重新下载
                    jQuery(".start_offlineWork_again").off().on('click', function (e) {

                        jQuery(".circle").remove()
                        self.clickNum++
                        jQuery(".load_fails_offline").hide()
                        jQuery(".load_loading_offline").show()
                        jQuery(".load_cancle_offline").show()
                        jQuery(".load_queding_offline").hide()
                        jQuery(".boxnum")[0].innerText = "0%"
                        native.checkOfflineCommitData(function (status, info, total, success, faild) {

                            if (status == 1) {
                                // 网络异常
                                app.methods.showToastBottom(info);
                                jQuery(".ilink-popup-backdrop").remove()
                            } else if (status == 2) {
                                // 无需要提交的作业数据
                                jQuery(".load_fails_offline").hide()
                                jQuery(".load_queding_offline").show()
                            } else {
                                self.proportion = parseInt((success + faild) / total * 100)
                                if (faild > 0 && self.proportion == 100) {
                                    self.progressBar(self.proportion)
                                } else {
                                    self.progressBar(self.proportion)
                                    yuanBox.gx(0)
                                }
                                if (faild > 0 && self.proportion == 100) {
                                    jQuery(".load_loading_offline").hide()
                                    jQuery(".load_fails_offline").show()
                                    if (self.clickNum >= 5) {
                                        jQuery(".start_offlineWork_cancel").hide()
                                        jQuery(".start_offlineWork_giveUp").show()
                                        jQuery(".ilink-popup-backdrop").remove()
                                    }
                                } else {
                                    
                                }
                            }
                        });


                    })
                    jQuery(".load_queding_offline").off().on('click', function (e) {
                        let self = this
                        jQuery(".ilink-popup-backdrop").remove()
                        native.saveDataByKey("IS_OFFLINE_MODULE", 0);
                        native.saveDataByKey("OFFLINE_SELECT_FLAG", 0)
                        native.saveDataByKey("IS_OFFLINE_POPUP", 0);
                        native.reloadH5FromFile();
                    })
                    jQuery(".start_offlineWork_giveUp").off().on('click', function (e) {
                        native.saveDataByKey("IS_OFFLINE_MODULE", 0);
                        native.saveDataByKey("OFFLINE_SELECT_FLAG", 0)
                        native.saveDataByKey("IS_OFFLINE_POPUP", 0);
                        native.reloadH5FromFile();
                    })
                })
            },
            progressBar: function (proportion) {
                let self = this
                function Yuan(id, num) {
                    this.box = document.getElementById(id);//获取节点
                    this.box.className = "wrap";

                    //创建节点circle
                    this.circle = document.createElement("div");
                    this.circle.className = "circle";
                    this.box.appendChild(this.circle);

                    //创建circle的子节点left
                    this.left = document.createElement("div");
                    this.left.className = "left";
                    this.circle.appendChild(this.left);

                    //创建circle的子节点right
                    this.right = document.createElement("div");
                    this.right.className = "right";
                    this.circle.appendChild(this.right);

                    //创建节点num
                    this.num = document.createElement("div");
                    this.num.className = "boxnum";
                    this.box.appendChild(this.num);
                    self.process = 0
                    if (num != 0) {
                        var timers = setInterval(function () {
                            if (self.process < num) {
                                self.process++
                                jQuery(".left").addClass('leftright')
                                jQuery(".right").addClass('leftright')
                                yuanBox.gx(self.process);
                                if (self.process >= 100) {

                                    clearInterval(timers);
                                    jQuery(".load_cancle_offline").hide()
                                    jQuery(".load_queding_offline").show()
                                    if (self.success == self.total) {
                                        jQuery(".load_cancle_offline").hide()
                                        jQuery(".load_ing_offline").hide()
                                        jQuery(".load_queding_offline").show()
                                        jQuery(".load_jieshu_offline").show()
                                    }
                                }
                                if (jQuery(".boxnum").length != 0) {
                                    jQuery(".boxnum")[0].innerText = self.process * 1 + '%';
                                } else {
                                    self.process = 0
                                    return
                                }

                                if (jQuery('.load_loading_offline').css('display') == "none") {

                                    self.process = 0
                                    yuanBox.gx(self.process);
                                    clearInterval(timers);
                                    // yuanBox.gx(i)
                                    return
                                }
                            } else {

                                clearInterval(timers);
                            }

                        }, 50);
                    }
                }

                Yuan.prototype.jz = function (num) {
                    let i = 0;
                    var that = this;
                    var int = setInterval(function () {
                        that.gx(num / 10 * i);
                        i++;
                        if (i > 10) {
                            clearInterval(int)
                        }
                    }, 200);
                }

                Yuan.prototype.gx = function (n) {

                    if (n <= 50) {
                        this.right.style.display = 'none';
                        this.circle.style.clip = 'rect(0, 100px, 100px, 50px)';
                    } else {
                        this.right.style.display = 'block';
                        this.circle.style.clip = 'rect(auto, auto, auto, auto)';
                    }
                    this.left.style.transform = 'rotate(' + n * 360 / 100 + 'deg)';

                }
                yuanBox = new Yuan('box3', proportion);
            },
            //展示列表
            showTaskList: function () {
                let self = this;
                jQuery("#delayTaskList_list").empty();
                Dao.getTestTasksByAccount({
                    account: userInfor.accountName,
                }, function (data, total) {
                    self.currentTestData = data
                    for (var i = 0; i < data.length; i++) {
                        var arrayData = {
                            "id": data[i].taskId,
                            "type": data[i].taskType,
                            "orgName": data[i].orgName,
                            "status": 1,
                            "taskName": data[i].name,
                            "orgId": data[i].orgId,
                            "complete": data[i].complete,
                            "total": data[i].total
                        }
                        if (self.currentTestData != '') {
                            if (data[i].taskType == 1 || data[i].taskType == 2) {
                                $("#delayTaskList_list").append(`
                                    <li id="delayTaskList_list_`+ data[i].id + `">
                                        <div class="each-list">
                                            <div class="delay-task-list-item-inner">
                                                <div class="item-title-row" id="task_`+ data[i].id + `" style="font-weight:bold">` + data[i].name + `</div>
                                                <div class="item-subtitle">
                                                    业主单位：<strong style="color:#333333">`+ data[i].orgName + `</strong>
                                                </div>
                                            </div>
                                            <div class="delay-task-list-button end-time" data-id="`+ data[i].id + `">
                                                <span class="right"> <a href="#" class="" >结束</a>
                                                </span>
                                            </div>
                                        </div>
                                    </li>
                                `);
                            } else {
                                //let delayTime = self.showHalfTime(data[i].endTime);
                                let delayTimeSplit = self.showHalfTime(data[i].endTime).split(":");
                                if (parseInt(delayTimeSplit[0]) >= 2) {
                                    $("#delayTaskList_list").append(`
                                        <li id="delayTaskList_list_`+ data[i].id + `">
                                            <div class="each-list">
                                                <div class="delay-task-list-item-inner">
                                                    <div class="delay-task-time over-one-hour" data-time="`+ data[i].endTime + `" data-id="` + data[i].id + `">
                                                        <span class="overtime h">`+ delayTimeSplit[0] + `</span> <span class="overdot">:</span>
                                                        <span class="overtime m">`+ delayTimeSplit[1] + `</span> <span class="overdot">:</span>
                                                        <span class="overtime s">`+ delayTimeSplit[2] + `</span> <span class="prompt-title">后失效</span>
                                                    </div>
                                                    <div class="item-title-row" id="task_`+ data[i].id + `">` + data[i].name + `</div>
                                                    <div class="item-subtitle">
                                                        业主单位：<strong style="color:#333333">`+ data[i].orgName + `</strong>
                                                    </div>
                                                </div>
                                                <div class="delay-task-list-button end-time" data-id="`+ data[i].id + `">
                                                    <span class="right"> <a href="#" class="" >结束</a>
                                                    </span>
                                                </div>

                                            </div>
                                        </li>
                                    `);
                                } else if (parseInt(delayTimeSplit[0]) < 2 && parseInt(delayTimeSplit[0]) >= 1) {
                                    $("#delayTaskList_list").append(`
                                        <li id="delayTaskList_list_`+ data[i].id + `">
                                            <div class="each-list">
                                                <div class="delay-task-list-item-inner">
                                                    <div class="delay-task-time over-one-hour" data-time="`+ data[i].endTime + `" data-id="` + data[i].id + `">
                                                    <span class="overtime h">`+ delayTimeSplit[0] + `</span> <span class="overdot">:</span>
                                                    <span class="overtime m">`+ delayTimeSplit[1] + `</span> <span class="overdot">:</span>
                                                    <span class="overtime s">`+ delayTimeSplit[2] + `</span> <span class="prompt-title">后失效</span>
                                                    </div>
                                                    <div class="item-title-row" id="task_`+ data[i].id + `" style="font-weight: bold;">` + data[i].name + `</div>
                                                    <div class="item-subtitle">
                                                        业主单位：<strong style="color:#333333">`+ data[i].orgName + `</strong>
                                                    </div>
                                                </div>
                                                <div class="delay-task-list-button-two">
                                                    <div class="left end-time" data-id="`+ data[i].id + `">
                                                        <a href="#" style="color: #999999;" class="" >结束</a>
                                                    </div>
                                                    <div class="right delay-close" data-time="`+ data[i].endTime + `" data-id="` + data[i].id + `">
                                                        <a href="#" class="" style="color:black">延时2小时</a>
                                                    </div>
                                                </div>
                                            </div>
                                        </li>
                                    `);
                                } else if (parseInt(self.minute) > 10) {
                                    $("#delayTaskList_list").append(`
                                        <li id="delayTaskList_list_`+ data[i].id + `">
                                            <div class="each-list">
                                                <div class="delay-task-list-item-inner">
                                                    <div class="delay-task-time over-ten-min" data-time="`+ data[i].endTime + `" data-id="` + data[i].id + `">
                                                    <span class="overtime h">`+ delayTimeSplit[0] + `</span> <span class="overdot">:</span>
                                                    <span class="overtime m">`+ delayTimeSplit[1] + `</span> <span class="overdot">:</span>
                                                    <span class="overtime s">`+ delayTimeSplit[2] + `</span> <span class="prompt-title">后失效</span>
                                                    </div>
                                                    <div class="item-title-row" id="task_`+ data[i].id + `" style="font-weight: bold;">` + data[i].name + `</div>
                                                    <div class="item-subtitle">
                                                        业主单位：<strong style="color:#333333">`+ data[i].orgName + `</strong>
                                                    </div>
                                                </div>
                                                <div class="delay-task-list-button-two">
                                                    <div class="delay-task-list-button-two">
                                                        <div class="left end-time" data-id="`+ data[i].id + `">
                                                            <a href="#" style="color: #999999;" class="">结束</a>
                                                        </div>
                                                        <div class="right delay-close" data-time="`+ data[i].endTime + `" data-id="` + data[i].id + `">
                                                            <a href="#" class="" style="color:black">延时2小时</a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </li>
                                    `);
                                } else {
                                    $("#delayTaskList_list").append(`
                                        <li id="delayTaskList_list_`+ data[i].id + `">
                                            <div class="each-list">
                                                <div class="delay-task-list-item-inner">
                                                    <div class="delay-task-time less-ten-min" data-time="`+ data[i].endTime + `" data-id="` + data[i].id + `">
                                                    <span class="overtime h">`+ delayTimeSplit[0] + `</span> <span class="overdot">:</span>
                                                    <span class="overtime m">`+ delayTimeSplit[0] + `</span> <span class="overdot">:</span>
                                                    <span class="overtime s">`+ delayTimeSplit[0] + `</span> <span class="prompt-title">后失效</span>
                                                    </div>
                                                    <div class="item-title-row" id="task_`+ data[i].id + `" style="font-weight: bold;">` + data[i].name + `</div>
                                                    <div class="item-subtitle">
                                                        业主单位：<strong style="color:#333333">`+ data[i].orgName + `</strong>
                                                    </div>
                                                </div>
                                                <div class="delay-task-list-button-two">
                                                    <div class="left end-time" data-id="`+ data[i].id + `">
                                                        <a href="#" style="color: #999999;" class="">结束</a>
                                                    </div>
                                                    <div class="right delay-close" data-time="`+ data[i].endTime + `" data-id="` + data[i].id + `">
                                                        <a href="#" class="" style="color:black">延时2小时</a>
                                                    </div>
                                                </div>
                                            </div>
                                        </li>
                                    `);
                                }
                            }
                            // 进入任务
                            jQuery("#task_" + data[i].id).off().click({ 'data': arrayData }, function (e) {
                                jQuery(".close-maintencePopup").click();
                                var data = e.data.data;
                                var taskType = data.type;
                                if (taskType == 1) { // 巡查
                                    app.router.navigate("/allBuild/maintainInspect/" + data.id + "/" + data.orgName + "/" + encodeURIComponent(data.taskName) + "/" + data.status + "/" + data.orgId + "/");
                                } // 保养 
                                else if (taskType == 2) {
                                    app.router.navigate("/allBuild/maintain/" + data.id + "/" + data.orgName + "/" + encodeURIComponent(data.taskName) + "/" + data.status + "/" + data.orgId + "/");
                                } //单点测试
                                else if (taskType == 3) {
                                    app.router.navigate("/allBuild/singleTest/" + data.id + "/" + data.orgName + "/" + encodeURIComponent(data.taskName) + "/" + data.status + "/" + data.orgId + "/");
                                } // 联动测试
                                else {
                                    if (data.total == data.complete) { //已完成
                                        app.router.navigate("/linkTestDetail/" + data.id + "/");
                                    } else {
                                        app.router.navigate("/linkTestTask/" + data.id + "/");
                                    }
                                }
                            });
                        }
                        // 开启定时任务
                        self.startPopupCountdown();

                        // 增加延时
                        jQuery(".delay-close").off().click(function () {
                            app.methods.showToastCenter("离线模式不支持延时操作")
                            // var endTime = $(this).attr("data-time");
                            // var id = $(this).attr("data-id");
                            // self.delayRemind(endTime,id);
                        });

                        // 结束测试
                        jQuery(".end-time").off().click(function () {
                            var id = $(this).attr("data-id");
                            self.isShowPop = true;
                            confimEndTest(id, function () {
                                setTimeout(function () {
                                    self.getTestTask();
                                    self.showTaskList();
                                    self.refreshTaskList();
                                }, 1000);
                            });
                        });
                    }

                    jQuery('#maintence_total')[0].innerText = total
                    if (data == '') {
                        jQuery("#delayTaskList_list").append(`<div class="no-data-img"><img src="` + listNoDataPic() + `"/></div>`);
                    }
                })
            },
            // 弹窗定时任务
            startPopupCountdown: function () {
                let self = this;
                clearInterval(self.downInterval_popup);
                self.downInterval_popup = setInterval(function () {
                    // 获取列表时间
                    let timaArrEl = $(".delay-task-time");
                    $(".delay-task-time .overtime").removeClass('orange green yellow');
                    for (let i = 0; i < timaArrEl.length; i++) {
                        let t = $(timaArrEl[i]).attr("data-time");
                        //let t = $(timaArrEl[i]).attr("data-time");
                        let dt = custom.showHalfTime(t).split(":");
                        if (parseInt(dt[0]) > 0) {
                            $(timaArrEl[i]).find(".overtime.h").html(dt[0]).addClass("green");
                            $(timaArrEl[i]).find(".overtime.m").html(dt[1]).addClass("green");
                            $(timaArrEl[i]).find(".overtime.s").html(dt[2]).addClass("green");
                            $(timaArrEl[i]).find(".prompt-title").addClass("green");
                        }
                        else if (parseInt(dt[0]) <= 0 && parseInt(dt[1]) > 9) {
                            $(timaArrEl[i]).find(".overtime.h").html(dt[0]).addClass("yellow");
                            $(timaArrEl[i]).find(".overtime.m").html(dt[1]).addClass("yellow");
                            $(timaArrEl[i]).find(".overtime.s").html(dt[2]).addClass("yellow");
                            $(timaArrEl[i]).find(".prompt-title").addClass("yellow");
                        }
                        else if (parseInt(dt[1]) <= 9) {
                            $(timaArrEl[i]).find(".overtime.h").html(dt[0]).addClass("orange");
                            $(timaArrEl[i]).find(".overtime.m").html(dt[1]).addClass("orange");
                            $(timaArrEl[i]).find(".overtime.s").html(dt[2]).addClass("orange");
                            $(timaArrEl[i]).find(".prompt-title").addClass("orange");
                        }

                        if ((parseInt(dt[0]) == 0) && (parseInt(dt[1]) == 0) && (parseInt(dt[2]) == 0)) {
                            clearInterval(self.downInterval_popup);
                            self.downInterval_popup = 0;
                            native.deleteGetTestTasksByAccountListData($(timaArrEl[i]).attr("data-id"))
                            self.showTaskList();
                            jQuery(".taskCountDownTimeTip").hide();
                        }
                    }
                }, 1000);
            },
            // 延时提醒
            delayRemind: function (time, id) {
                let self = this;
                // 隐藏原先列
                jQuery("#delayTaskList_list_" + id + " .each-list").slideUp(300);
                jQuery("#delayTaskList_list_" + id + " .delay-class").remove();
                let delayTimeSplit = self.showHalfTime(time).split(":");
                let timeTwo = moment(time).add(2, 'h').format("YYYY-MM-DD HH:mm:ss");
                let delayTimeSplitTwo = self.showHalfTime(timeTwo).split(":");
                let delayHtml = `
                <div class="delay-class delay-current-time" id="delay-con-`+ id + `" data-old="` + time + `" data-new="` + timeTwo + `">
                <div class="delay-class-body" style="padding:0px 15px">
                    <div class="delay-class-body-hint">请确认是否延时2小时后提醒？</div>
                    <div class="delay-class-body-time">
                    <div class="prompt-class-top old-time">
                        <span class="overtime h" id="hour">`+ delayTimeSplit[0] + `</span>
                        <span class="overdot">:</span>    
                        <span class="overtime m" id="minute">`+ delayTimeSplit[1] + `</span>
                        <span class="overdot">:</span>
                        <span class="overtime s" id="second">`+ delayTimeSplit[2] + `</span>
                    </div>
                    <div class="arrow-class-center">
                            <span>+2</span>
                            <div><i class="iconfont icon-single_arrow"></i></div>
                    </div>
                    <div class="prompt-class-top new-time">
                        <span class="overtime h" id="newHour">`+ delayTimeSplitTwo[0] + `</span>
                        <span class="overdot">:</span>    
                        <span class="overtime m" id="newMinute">`+ delayTimeSplitTwo[1] + `</span>
                        <span class="overdot">:</span>
                        <span class="overtime s" id="newSecond">`+ delayTimeSplitTwo[2] + `</span>
                    </div>
                    </div>
                    <div class="prompt-class-button">
                    <div class="block">
                        <p class="row">
                            <button class="col button button-big left" id="delay_cancel_`+ id + `" data-id="` + id + `">取消</button>
                            <button class="col button button-big right" id="delay_confim_`+ id + `" data-id="` + id + `">确定延时</button>
                        </p>
                    </div>
                    </div>
                </div>
                </div>`;

                jQuery("#delayTaskList_list_" + id).append(delayHtml);

                jQuery("#delay_cancel_" + id).off().click(function (event) {
                    let id = $(this).attr("data-id");
                    jQuery("#delay-con-" + id).slideUp(300);
                    jQuery("#delayTaskList_list_" + id + " .each-list").slideDown();
                });

                jQuery("#delay_confim_" + id).off().click(function (event) {
                    let id = $(this).attr("data-id");
                    common.loading(1);
                    Dao.delayTestTime({
                        id: id,
                    }, function (data) {
                        // 删除延时提醒
                        jQuery("#delayTaskList_list_" + id + " .delay-class").remove();
                        jQuery("#delayTaskList_list_" + id).append(self.tipSimple(1));
                        common.loading(0);
                        setTimeout(function () {
                            jQuery("#delayTaskList_list_" + id + " .hint-layer").remove();
                            self.showTaskList();
                            self.getTestTask();
                        }, 3000);
                    }, true);
                });

                self.startDelayCountdown();
            },
            // 是否有测试任务
            getTestTask: function () {
                let self = this;
                currentTestData = [];
                self.clearAllInter();
                //jQuery(".taskCountDownTimeTip").remove();
                Dao.getTestTasksByAccount({
                    account: userInfor.accountName,
                }, function (data, total) {
                    currentTestData = data;
                    if (data && data.length > 0) {
                        // 保养 维保
                        if (data[0].taskType == 1 || data[0].taskType == 2) {
                            self.isHasTest = false;
                        } else {
                            self.isHasTest = true;
                        }
                        self.showHelperEnter();
                    }
                }, false);
            },
            // 清除定时任务
            clearAllInter: function () {
                if (self.downInterval) {
                    clearInterval(self.downInterval);
                    self.downInterval = 0;
                }
                if (self.downInterval_delay) {
                    self.downInterval_delay = 0;
                }
                if (self.downInterval_popup) {
                    clearInterval(self.downInterval_popup);
                    self.downInterval_popup = 0;
                }
                if (self.downInterval_pop) {
                    clearInterval(self.downInterval_pop);
                    self.downInterval_pop = 0;
                }
                if (self.downInterval_task) {
                    clearInterval(self.downInterval_task);
                    self.downInterval_task = 0;
                }
            },
            // 维保助手里面结束任务后，如果当前是在列表页面（保养，维保巡查，单点测试，联动测试）要刷新当前列表
            refreshTaskList: function () {
                let el = app.view.current.el.f7View.router.currentPageEl.f7Component;
                if (el && el.pageName == "maintain") {
                    el.closeTaskBackRefreshList()
                }
                else if (el && el.pageName == "linkTest") {
                    el.closeTaskBackRefreshList()
                }
                else if (el && el.pageName == "singleTest") {
                    el.closeTaskBackRefreshList()
                }
                else if (el && el.pageName == "maintainInspect") {
                    el.closeTaskBackRefreshList()
                }
            },
            // 延时定时任务
            startDelayCountdown: function () {
                let self = this;
                clearInterval(downInterval_delay);
                downInterval_delay = setInterval(function () {
                    $(".delay-current-time .old-time").removeClass('orange green yellow');

                    let oldD = $(".delay-current-time").attr("data-old");
                    let newD = $(".delay-current-time").attr("data-new");
                    let oldD_delay = self.showHalfTime(oldD).split(":");
                    let newD_delay = self.showHalfTime(newD).split(":");
                    if (parseInt(oldD_delay[0]) > 0) {
                        $(".delay-current-time .old-time").find(".overtime.h").html(oldD_delay[0]).addClass("green");
                        $(".delay-current-time .old-time").find(".overtime.m").html(oldD_delay[1]).addClass("green");
                        $(".delay-current-time .old-time").find(".overtime.s").html(oldD_delay[2]).addClass("green");

                        $(".delay-current-time .new-time").find(".overtime.h").html(newD_delay[0]);
                        $(".delay-current-time .new-time").find(".overtime.m").html(newD_delay[1]);
                        $(".delay-current-time .new-time").find(".overtime.s").html(newD_delay[2]);
                    }
                    else if (parseInt(oldD_delay[1]) > 9) {
                        $(".delay-current-time .old-time").find(".overtime.h").html(oldD_delay[0]).addClass("yellow");
                        $(".delay-current-time .old-time").find(".overtime.m").html(oldD_delay[1]).addClass("yellow");
                        $(".delay-current-time .old-time").find(".overtime.s").html(oldD_delay[2]).addClass("yellow");

                        $(".delay-current-time .new-time").find(".overtime.h").html(newD_delay[0]);
                        $(".delay-current-time .new-time").find(".overtime.m").html(newD_delay[1]);
                        $(".delay-current-time .new-time").find(".overtime.s").html(newD_delay[2]);
                    }
                    else if (parseInt(oldD_delay[2]) <= 9) {
                        $(".delay-current-time .old-time").find(".overtime.h").html(oldD_delay[0]).addClass("orange");
                        $(".delay-current-time .old-time").find(".overtime.m").html(oldD_delay[1]).addClass("orange");
                        $(".delay-current-time .old-time").find(".overtime.s").html(oldD_delay[2]).addClass("orange");

                        $(".delay-current-time .new-time").find(".overtime.h").html(newD_delay[0]);
                        $(".delay-current-time .new-time").find(".overtime.m").html(newD_delay[1]);
                        $(".delay-current-time .new-time").find(".overtime.s").html(newD_delay[2]);
                    }
                }, 1000);
            },
            // 展示助手入口
            // flag 1:
            showHelperEnter: function () {
                let self = this;
                jQuery(".taskCountDownTimeTip").hide();
                if (self.isHasTest) {
                    let time = '0';
                    // 开启定时任务
                    for (var i = 0; i < currentTestData.length; i++) {
                        let datatime = custom.showHalfTime(currentTestData[i].endTime).split(":")
                        if (currentTestData[i].taskType == 3 || currentTestData[i].taskType == 4) {
                            if (datatime[0] != "00" || datatime[1] != "00" || datatime[2] != "00") {
                                self.currentTestEndTime = currentTestData[i].endTime;
                                self.startCountdown();
                                break;
                            }
                            else {
                                self.isHasTest = false;
                                app.methods.showToastCenter(currentTestData[i].name + "已到期自动关闭")
                                custom.getTestTask();
                                break;
                            }
                        } else {
                            app.methods.showToastCenter(currentTestData[i].name + "已到期自动关闭")
                            custom.getTestTask();
                        }

                    }
                }
            },
            // 悬浮窗定时任务
            startCountdown: function () {
                let self = this;
                clearInterval(self.downInterval);
                self.downInterval = setInterval(function () {
                    custom.showHelperEnter();
                    $("#contTime").html(custom.showHalfTime());
                    var time = custom.showHalfTime();
                    var timeArr = time.split(":");
                    if (!self.isShowPop) {
                        if (parseInt(timeArr[0]) == 0 && parseInt(timeArr[1]) <= 2) {
                            self.isShowPop = true;
                            // for(var i = 0;i<currentTestData.length;i++){
                            // 	let hwy = custom.showHalfTime(currentTestData[i].endTime).split(":");
                            // 	if(hwy[0]==="01" && hwy[1]==="12"&& hwy[2]==="00"){
                            // 		threeMinPop(currentTestData[i]);
                            // 	}
                            // }
                            //self.threeMinPop(currentTestData[0]);
                        } else if (parseInt(timeArr[0]) == 0 && parseInt(timeArr[1]) == 3 && parseInt(timeArr[1]) == 0) {
                            self.isShowPop = true;
                            //self.threeMinPop(currentTestData[0]);
                        }
                    }
                }, 1000);
            },
            //倒计时3分钟之内的弹框
            threeMinPop: function (data) {
                clearInterval(downInterval_pop);
                var delayTime = custom.showHalfTime(data.endTime);
                let delayTimeSplit = custom.showHalfTime(data.endTime).split(":");
                let name = data.orgName;
                let html = `
                    <div class="only-delay-task" data-id="`+ data.id + `"
                        data-time="`+ data.endTime + `">
                            <div class="only-delay-task-inner">
                            <div class="only-delay-task-time less-three-min" data-time="`+ data.endTime + `">
                                <span class="overtime h">`+ delayTimeSplit[0] + `</span> <span class="overdot">:</span>
                                <span class="overtime m">`+ delayTimeSplit[0] + `</span> <span class="overdot">:</span>
                                <span class="overtime s">`+ delayTimeSplit[0] + `</span> <span class="prompt-title">后失效</span>
                            </div>
                            <div class="task-title-row" id="task_`+ data.id + `">` + data.name + `</div>
                            <div class="task-subtitle">
                                业主单位：<strong style="color:#333333">`+ data.orgName + `</strong>
                            </div>
                            </div>
                            <div class="delay-task-button-two">
                            <div class="left end-time" data-id="`+ data.id + `">
                                <a href="#" style="color: #999999;" class="">结束</a>
                            </div>
                            <div class="right add-delay" style="background:#999999" data-time="`+ data.endTime + `" data-id="` + data.id + `">
                                <a href="#" class="" style="color:black">延时2小时</a>
                            </div>
                            </div>
                        </div>`;
                openLayer(html, (el) => {
                    clearInterval(downInterval_pop);
                    downInterval_pop = setInterval(function () {
                        let time = $(".only-delay-task-time").attr("data-time");
                        let time_delay = custom.showHalfTime(time).split(":");
                        $(".only-delay-task-time").find(".overtime.h").html(time_delay[0]);
                        $(".only-delay-task-time").find(".overtime.m").html(time_delay[1]);
                        $(".only-delay-task-time").find(".overtime.s").html(time_delay[2]);
                        if (time_delay.join(":") == '00:00:00') {
                            clearInterval(downInterval_pop);
                            var id = jQuery(".only-delay-task").attr("data-id");
                            self.currentTestEndTime = data.endTime;
                            //forceClose(name);
                            setTimeout(function () {
                                custom.getTestTask();
                                custom.showTaskList();
                                custom.refreshTaskList();
                            }, 1000);
                        }
                    }, 1000);

                    // 增加延时
                    jQuery(".add-delay").off().click(function () {
                        app.methods.showToastCenter("离线模式不支持延时操作")
                        // var endTime = $(this).attr("data-time");
                        // var id = $(this).attr("data-id");
                        // delayRemind(endTime,id);
                    });

                    // 结束测试
                    jQuery(".end-time").off().click(function () {
                        var id = $(this).attr("data-id");
                        confimEndTest(id, function () {
                            setTimeout(function () {
                                custom.getTestTask();
                                custom.showTaskList();
                                custom.refreshTaskList();
                            }, 1000);
                        });
                    });
                })
            },
            /**
             * 无需操作的提示信息框 flag的值： 1—延时操作。2—结束测试. 3—扫码提示 4—倒计时提示
             */
            tipSimple: function (flag, info) {
                if (flag == 1) {  // 延时成功
                    var html = `<div class="hint-layer">
                        <div class="hint-icon delay-icon"><i class="iconfont icon-duigou1"></i></div>
                        </div>`;
                }

                if (flag == 2) { // 结束成功
                    var html = `<div class="hint-layer">
                        <div class="hint-icon end-icon"><i class="iconfont icon-duigou1"></i></div>
                        <div class="hint-content prompt-content">结束成功</div>
                        </div>`;
                }

                if (flag == 3) {  // 扫码提示
                    var html = `<div class="hint-layer">
                        <div class="hint-icon"><i class="iconfont icon-point"></i></div>
                        <div class="hint-content">`+ info + `</div>
                        </div>`;
                }

                if (flag == 4) { // 2小时候再提醒
                    var html = `<div class="hint-layer">
                        <div class="hint-icon end-icon"><i class="iconfont icon-naozhong-"></i></div>
                        <div class="hint-content prompt-content">2小时候再次提醒</div>
                        </div>`;
                }
                openLayer(html, (el) => { })
            },
            // 返回剩余时间
            showHalfTime: function (time) {
                let self = this;
                let now = moment().format("YYYY-MM-DD HH:mm:ss");
                let a = moment(time ? time : self.currentTestEndTime);
                let b = moment(now); // 当前时间
                let tempTime = moment.duration(a - b);
                let h = tempTime.hours();
                let m = tempTime.minutes();
                let s = tempTime.seconds();
                let timeHour = "";
                let timeMinute = "";
                let timeMsecond = "";

                if (moment(time ? time : self.currentTestEndTime).isAfter(common.transtimestamp(new Date()))) {
                    timeHour = ((h < 10) ? ("0" + h) : h);
                    timeMinute = ((m < 10) ? ("0" + m) : m);
                    timeMsecond = ((s < 10) ? ("0" + s) : s);
                }
                // 超过剩余时间
                else {
                    timeHour = "00";
                    timeMinute = "00";
                    timeMsecond = "00";
                }
                let remainingTimeHour = timeHour + ":" + timeMinute + ":" + timeMsecond;
                let remainingTimeMinute = "00:" + timeMinute + ":" + timeMsecond;
                let remainingTimeSecond = "00:" + timeMinute + ":" + timeMsecond;
                let newTime = '';
                if (!time) {
                    $(".taskCountDownTimeTip").removeClass('orange green yellow');
                }
                if (parseInt(timeHour) > 0) {
                    newTime = remainingTimeHour;
                    if (!time) {
                        $(".taskCountDownTimeTip").addClass("green");
                    }
                }
                else if (parseInt(timeHour) <= 0 && parseInt(timeMinute) > 9) {
                    newTime = remainingTimeMinute;
                    if (!time) {
                        $(".taskCountDownTimeTip").addClass("yellow");
                    }
                }
                else if (parseInt(timeMinute) <= 9) {
                    newTime = remainingTimeSecond;
                    if (!time) {
                        $(".taskCountDownTimeTip").addClass("orange");
                    }
                }
                return newTime;
            },
        },
        on: {
            pageInit: function (e, page) {
                var self = this;
                var $ = self.$;
                notShow = true;//全局变量定义当前离线维保页面不要维保助手
                self.showTaskList()
                common.loading(0);
                if (notShow) { $("#taskCountDownTimeTip").hide() }
                var IS_OFFLINE_DAYCHECK = native.getDataByKey("IS_OFFLINE_DAYCHECK");
                var IS_OFFLINE_DAYWEIBAO = native.getDataByKey("IS_OFFLINE_DAYWEIBAO");
                if (IS_OFFLINE_DAYCHECK == 0) {
                    jQuery(".apply-permiss-offline").hide()
                }
                if (IS_OFFLINE_DAYWEIBAO == 0) {
                    jQuery(".offlineWork_content").hide()
                }
            },
            pageBeforeRemove: function (e, page) {
                var self = this;
                if (notShow) { $("#taskCountDownTimeTip").show() }
                notShow = false;
            },
            pageAfterIn: function (e, page) {
                var self = this;
                var $ = self.$;
                self.showTaskList()
                notShow = true;//全局变量定义当前离线维保页面不要维保助手
                if (notShow) { $("#taskCountDownTimeTip").hide() }
                contextPath=native.getDataByKey('locationOrigin')+'/'
            },
        }
    }
</script>
<style scoped>
    .offline_title {
        font-size: 15px;
    }

    .offline_over_work {
        width: 100px;
        border: 1px #69ba71 solid;
        text-align: center;
        height: 30px;
        line-height: 30px;
        font-size: 15px;
        color: #69ba71;
        margin-top: -29px;
        position: absolute;
        margin-left: calc(100% - 133px);
    }

    .item-media {
        padding-top: 8px;
        min-width: 40px;
    }

    .greenC {
        background-color: #69ba71;
    }

    .item-media-icon {
        width: 30px;
        height: 30px;
        border-radius: 4px;
        text-align: center;
        line-height: 30px;
    }

    .item-media-icon i {
        color: #fff;
        font-size: 19px;
    }

    .item-title {
        margin-top: -25px;
        margin-left: 46px;
        font-size: 15px;
    }

    .apply-permiss-offline {
        padding: 10px;
        height: 50px;
    }

    .offlineWork_content_title {
        padding: 20px;
    }

    .offlineWork_content_bto {
        font-weight: bold;
    }

    .delay-close {
        background: #999999;
    }
</style>